package com.mogist.hqc.module.order.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.mogist.hqc.R
import com.mogist.hqc.entitys.response.OrderVo
import com.mogist.hqc.util.Util
import talex.zsw.basecore.util.glide.GlideTool

/**
 * 作用：订单列表
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
class OrderAdapter : BaseQuickAdapter<OrderVo, BaseViewHolder>(R.layout.item_order)
{
    override fun convert(helper: BaseViewHolder, item: OrderVo)
    { //iTvOrderNo iTvStatus iIvIcon iTvTitle iTvCount iTvPrice
        // iLLAction iTvCancel iTvRefund iTvComment iTvPay iTvRefundStr
        var contStr = ""
        if (item.amountAdult > 0)
        {
            contStr += item.amountAdult.toString() + "成人  "
        }
        if (item.amountChildren > 0)
        {
            contStr += item.amountAdult.toString() + "儿童"
        }
        helper.setText(R.id.iTvOrderNo, "订单号 ${item.orderNo}")
                .setText(R.id.iTvStatus, Util.getOrderStatus(item.orderStatus, item.payStatus))
                .setText(R.id.iTvTitle, item.pdtName + " " + item.proName)
                .setText(R.id.iTvCount, contStr)
                .setText(R.id.iTvPrice, item.amountAll)
                .addOnClickListener(R.id.iTvCancel)
                .addOnClickListener(R.id.iTvRefund)
                .addOnClickListener(R.id.iTvComment)
                .addOnClickListener(R.id.iTvPay)
        when (item.orderStatus)
        { // NEW("NEW", "新建订单"), FAILED("FAILED", "失效订单"), SUCCESS("SUCCESS", "成功订单"), FINISH("FINISH", "结束订单"), APPRAISED("APPRAISED", "已评价");
            "NEW"       ->
            {
                helper.setGone(R.id.iLLAction, true)
                        .setGone(R.id.iTvCancel, true)
                        .setGone(R.id.iTvRefund, false)
                        .setGone(R.id.iTvComment, false)
                        .setGone(R.id.iTvPay, true)
                        .setGone(R.id.iTvRefundStr, false)
            }
            "FAILED"    ->
            {
                helper.setGone(R.id.iLLAction, false)
            }
            "SUCCESS"   ->
            {
                helper.setGone(R.id.iLLAction, false)
                        .setGone(R.id.iTvCancel, false)
                        .setGone(R.id.iTvRefund, true)
                        .setGone(R.id.iTvComment, false)
                        .setGone(R.id.iTvPay, false)
                        .setGone(R.id.iTvRefundStr, false)
            }
            "FINISH"    ->
            {
                if ("PAYED" == item.payStatus)
                {
                    helper.setGone(R.id.iLLAction, true)
                            .setGone(R.id.iTvCancel, false)
                            .setGone(R.id.iTvRefund, false)
                            .setGone(R.id.iTvComment, true)
                            .setGone(R.id.iTvPay, false)
                            .setGone(R.id.iTvRefundStr, false)
                }
                else
                {
                    helper.setGone(R.id.iLLAction, false)
                }
            }
            "APPRAISED" ->
            {
                helper.setGone(R.id.iLLAction, false)
            }
            "REFUNDING" ->
            {
                helper.setGone(R.id.iLLAction, false)
            }
        }
        GlideTool.loadImg(helper.getView(R.id.iIvIcon), item.pdtImg) // TODO 订单中的产品图片?
    }
}